//
//  UserAccountTradingController.m
//  CheekiOS
//
//  Created by mac on 2017/6/21.
//  Copyright © 2017年 mac. All rights reserved.
//

#import "UserAccountTradingController.h"
//交易明细
#import "UserTradingCell.h"
@interface UserAccountTradingController ()<UITableViewDelegate, UITableViewDataSource>

@property (nonatomic, strong) UITableView *tableView;
@property (nonatomic, strong) NSMutableArray *dataSource;
@property (nonatomic, assign) charmDetailListType  charmDetailListType;
@property (nonatomic, strong) UserCharmDetailListModel *model;

@end

@implementation UserAccountTradingController

- (void)viewDidLoad {
    [super viewDidLoad];
    [self setNavgationBarHidden];
    
    
    self.charmDetailListType = KCharmDetailListTypeAll;
    UIView *bgView = [[UIView alloc] initWithFrame:CGRectMake(0, 0, KScreenWidth, 64)];
    bgView.backgroundColor = Colorbackground;
    [self.view addSubview:bgView];
    
    
    UIButton *btn = [[UIButton alloc] initWithFrame:CGRectMake(22, 19.5, 44, 44)];
    btn.contentHorizontalAlignment=UIControlContentHorizontalAlignmentLeft ;//设置文字位置，现设为居左，默认的是居中
    
    [btn setImage:[UIImage imageNamed:@"back"] forState:UIControlStateNormal];
    btn.imageEdgeInsets = UIEdgeInsetsMake(0, 5.5, 0, 0);
    [btn addTarget:self action:@selector(backActionbtn) forControlEvents:UIControlEventTouchUpInside];
    CGFloat TopsegmentFloat ;
    
    if ([[UIDevice currentDevice] userInterfaceIdiom] == UIUserInterfaceIdiomPad){
        NSLog(@"ipad");
        TopsegmentFloat =0;
        
    }else{
        TopsegmentFloat = 16;
        
        NSLog(@"iphone or ipod");
    }
    
    UILabel *titleLab = [[UILabel alloc] initWithFrame:CGRectMake(0, TopsegmentFloat, KScreenWidth, 44*SCREEN_WIDTH_RATIO47)];
    titleLab.text = @"账户明细";
    titleLab.font = [UIFont systemFontOfSize:18];
    titleLab.textColor = ColorI(0x2e353f);
    titleLab.textAlignment = NSTextAlignmentCenter;
    [bgView addSubview:titleLab];
    [bgView addSubview:btn];


    if (!_tableView) {
        self.tableView = [[UITableView alloc] initWithFrame:CGRectMake(0, bgView.bottom, KScreenWidth, KScreenHeight-49) style:UITableViewStylePlain];
        self.tableView.delegate = self;
        self.tableView.dataSource = self;
        self.tableView.backgroundColor = [UIColor whiteColor];
        self.tableView.separatorStyle = UITableViewCellSeparatorStyleNone;
        [self.view addSubview:_tableView];
    }
    

    [self requestDate];
}

- (void)backActionbtn{
    [self.navigationController popViewControllerAnimated:YES];
}

-(NSInteger)numberOfSectionsInTableView:(UITableView *)tableView{
    return 1;
}

-(NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section{
    
    return self.dataSource.count;
    
}

-(UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath{
    UserTradingCell *cell = [UserTradingCell cellWithTableView:tableView indexPath:indexPath];
    _model = _dataSource[indexPath.row];
    cell.model = _model;
    return cell;
}

-(CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath{
    return 70;
}

- (void)requestDate{
    [HcardHttpmanager getCharmDetailListWithType:self.charmDetailListType withPage:1 withRows:10 success:^(id result) {
    
        
        _dataSource = result;
        [self.tableView reloadData];
   
    
    } failure:^(NSError *error) {
        
    }];

}

@end
